﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsView;
using WindowsFormsModel.BusinessObjects;

namespace WindowsFormsPresenter.Province
{
    public class ProvincePresenter : Presenter<IProvinceView>
    {
        public ProvincePresenter(IProvinceView view)
            : base(view)
        {
        }

        public void Display(string provinceCode)
        {
            if (provinceCode == null) return;

            var province = Model.GetProvince(provinceCode);

            View.ProvinceCode = province.ProvinceCode;
            View.ProvinceName = province.ProvinceName;
            View.CreateDate = province.CreateDate;
            View.ModifiedDate = province.ModifiedDate;
            View.Description = province.Description;
            View.IsActive = province.IsActive;
        }

        public int Save(bool action)
        {
            var provinceCode = new ProvinceModel
            {
                ProvinceCode = View.ProvinceCode,
                ProvinceName = View.ProvinceName,
                CreateDate = View.CreateDate,
                ModifiedDate = View.ModifiedDate,
                Description = View.Description,
                IsActive = View.IsActive
            };

            if (action == true)
                return Model.AddProvince(provinceCode);
            else
                return Model.UpdateProvince(provinceCode);
        }

        public int Delete(string provinceCode)
        {
            return Model.DeleteProvince(provinceCode);
        }
    }
}
